import React from 'react'
import styles from './index.module.scss'
import { Button, Form, Input, message } from 'antd'
import { loginAdminApi } from '@/common/api';
import { setLs } from '@/common/common';
import { useNavigate } from 'react-router-dom';
export default function ManageLogin() {
  const [form] = Form.useForm();
  const navigate = useNavigate()
  const loginFn = async() => {
    form.validateFields().then(async (values) => {
      const RES = await loginAdminApi(values)
      if (RES.code == 200) {
        setLs(RES.data, 'admin')
        navigate("/manageMent")
        message.success(RES.msg)
      }
    }).catch((err) => {
      console.log(err);
    })
  }
  return (
    <div className={styles.ManageLogin}>
      <div className='login'>
        <h2>趣纷享后台登录系统</h2>
          <Form
          form={form}
          >
              <Form.Item
                label="账号"
            name="username"
            rules={[{required:true,message:'请填写账号'}]}
              >
               <Input />
          </Form.Item>
          <Form.Item
                label="密码"
            name="password"
            rules={[{required:true,message:'请填写密码'}]}
              >
               <Input />
          </Form.Item>
          <Button onClick={loginFn}>登录</Button>
        </Form>
        
      </div>
      
    </div>
  )
}
